"""
营销 - 商户活动余额查询模型
"""

from typing import Dict, Any, List
from jlpay.model.base import OrgBaseReq, BaseResponse


class MerchantActivityBalanceQueryRequest(OrgBaseReq):
    """商户活动余额查询请求"""
    
    def __init__(self):
        """初始化商户活动余额查询请求"""
        super().__init__()
        self.act_id = None  # 活动ID
        self.merch_no = None  # 商户号
    
    def set_act_id(self, act_id: str):
        """
        设置活动ID
        
        Args:
            act_id: 活动id
            
        Returns:
            MerchantActivityBalanceQueryRequest实例
        """
        self.act_id = act_id
        return self
    
    def set_merch_no(self, merch_no: str):
        """
        设置商户号
        
        Args:
            merch_no: 商户号
            
        Returns:
            MerchantActivityBalanceQueryRequest实例
        """
        self.merch_no = merch_no
        return self
    
    def path(self) -> str:
        """
        获取接口路径
        
        Returns:
            接口路径
        """
        return "/open/org/bank/act-bridge/act-merch/query"
    
    def to_dict(self) -> Dict[str, Any]:
        """
        将请求对象转换为字典，过滤掉值为None的字段
        
        Returns:
            字典对象
        """
        return {k: v for k, v in self.__dict__.items() if not k.startswith('_') and v is not None}


class MerchantActivityBalanceData:
    """商户活动余额数据"""
    
    def __init__(self):
        """初始化商户活动余额数据"""
        self.act_id = None  # 活动ID
        self.merch_no = None  # 商户号
        self.term_no = None  # 终端号
        self.sort_value = None  # 计费类型
        self.total_quota = None  # 总额度
        self.used_quota = None  # 已使用额度
        self.remaining_quota = None  # 剩余额度
        self.start_time = None  # 开始时间
        self.end_time = None  # 结束时间
        self.status = None  # 状态
    
    def set_act_id(self, act_id: str):
        """设置活动ID"""
        self.act_id = act_id
        return self
    
    def set_merch_no(self, merch_no: str):
        """设置商户号"""
        self.merch_no = merch_no
        return self
    
    def set_term_no(self, term_no: str):
        """设置终端号"""
        self.term_no = term_no
        return self
    
    def set_sort_value(self, sort_value: str):
        """设置计费类型"""
        self.sort_value = sort_value
        return self
    
    def set_total_quota(self, total_quota: str):
        """设置总额度"""
        self.total_quota = total_quota
        return self
    
    def set_used_quota(self, used_quota: str):
        """设置已使用额度"""
        self.used_quota = used_quota
        return self
    
    def set_remaining_quota(self, remaining_quota: str):
        """设置剩余额度"""
        self.remaining_quota = remaining_quota
        return self
    
    def set_start_time(self, start_time: str):
        """设置开始时间"""
        self.start_time = start_time
        return self
    
    def set_end_time(self, end_time: str):
        """设置结束时间"""
        self.end_time = end_time
        return self
    
    def set_status(self, status: str):
        """设置状态"""
        self.status = status
        return self
    
    def to_dict(self) -> Dict[str, Any]:
        """
        将对象转换为字典
        
        Returns:
            字典对象
        """
        return {k: v for k, v in self.__dict__.items() if v is not None}


class MerchantActivityBalanceQueryResponse(BaseResponse):
    """商户活动余额查询响应"""
    
    def __init__(self, response_dict=None):
        """
        初始化商户活动余额查询响应
        
        Args:
            response_dict: 响应字典
        """
        super().__init__(response_dict)
        self.data = []  # 商户活动余额数据列表
        
        if response_dict and 'data' in response_dict:
            if isinstance(response_dict['data'], list):
                self.data = [MerchantActivityBalanceData() for _ in response_dict['data']]
                for i, item in enumerate(response_dict['data']):
                    for key, value in item.items():
                        if hasattr(self.data[i], f'set_{key}'):
                            getattr(self.data[i], f'set_{key}')(value)
    
    def to_dict(self) -> Dict[str, Any]:
        """
        将响应对象转换为字典
        
        Returns:
            字典对象
        """
        data = super().to_dict()
        if self.data:
            data['data'] = [item.to_dict() for item in self.data]
        return data 